package com.advertisementsystem.Enum;

import java.util.Comparator;
import java.util.List;

public enum RoleTypeEnum {
    ADMIN(1, "管理员"),
    ADVERTISER(2, "广告主"),
    DEVICE_OWNER(3, "设备主");

    private final Integer code;
    private final String name;

    RoleTypeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public static String getNameByCode(Integer code) {
        if (code == null) {
            return "";
        }
        for (RoleTypeEnum type : values()) {
            if (type.getCode().equals(code)) {
                return type.getName();
            }
        }
        return "";
    }

    // getter方法
    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }
    public static RoleTypeEnum getHighestRole(List<String> roleCodes) {
        return roleCodes.stream()
                .map(RoleTypeEnum::valueOf)
                .max(Comparator.comparingInt(RoleTypeEnum::getCode))
                .orElse(ADVERTISER);
    }
}